#!/usr/bin/env python
# -*- coding:utf-8 -*-
import string, random

# 生成单个特殊字符
def rand_punctuation():
    return random.choice(string.punctuation)

# 生成单个字母
def rand_letter():
    return random.choice(string.ascii_letters)

# 生成单个数字
def rand_digit():
    return str(random.randint(0, 9))

def gen_password(require_length):
    pwd_list = []

    # 增加一个数字
    pwd_list.append(rand_digit())

    # 增加一个特殊字符
    pwd_list.append(rand_punctuation())

    # 增加字母，数量是总数-2
    for _ in range(require_length - 2):
        pwd_list.append(rand_letter())

    # 乱序列表
    random.shuffle(pwd_list)

    # 列表转字符串
    pwd_str = ("".join(pwd_list))
    return pwd_str

if __name__ == '__main__':
    while True:
        try:
            pwd_length = eval(input("please input the length of the password: "))
        except NameError as err:
            print("The input is not a number, please input again!")
            continue

        if pwd_length < 8 or pwd_length > 20:
            print("The length must be in 8 and 20!")
            continue

        print("The password length is : {0}".format(pwd_length))
        stu_no_list = ["2201220096","2201220098","2201220114","2201220137","2201220086"]
        stu_no_with_password = {}
        for stu_no in stu_no_list:
            password = gen_password(pwd_length)
            stu_no_with_password[stu_no] = password

        print("The password map is : {0}".format(stu_no_with_password))
